<?php
/**
 * User: wangxiaoxiao
 * Date: 2020年6月29日  0029
 * Time: 下午 18:07
 * Description: xhprof性能测试
 */
namespace api\event;

use XHProfRuns_Default;
use yii\base\Event;

class xhprofEvent extends Event {

    /**
     * User: wangxiaoxiao
     * Description: xhprof头部
     */
    function xhprofStart(){
        xhprof_enable();
    }


    /**
     * User: wangxiaoxiao
     * Description: xhprof尾部
     * @param $event
     */
    function xhprofEnd(){
        $xhprof_data = xhprof_disable();
        $XHPROF_ROOT = __DIR__;
        include_once $XHPROF_ROOT."/../web/xhprof_lib/utils/xhprof_lib.php";
        include_once $XHPROF_ROOT."/../web/xhprof_lib/utils/xhprof_runs.php";
        $xhprof_runs = new XHProfRuns_Default();
        $route = 'xhprof';
        $run_id = $xhprof_runs->save_run($xhprof_data, $route);
        echo 'xhprof统计结果:';
        $domain = $_SERVER['SERVER_NAME'];
        $url = "http://".$domain."/xhprof_html/index.php?run=$run_id&source=$route";
        echo $url.PHP_EOL;
        echo '数据返回:';
    }
}